import axios from 'axios'
import toast from '../js/toast'
let axiosInstance = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  headers: {
    'Content-Type': 'application/json',
    'Access-Control-Allow-Origin': '*', 
    'Cache-Control': 'no-cach'
  },
  withCredentials: 'include',
  transformRequest: [function (data) {
    if (data && data.constructor && data.constructor.name === 'FormData') {
      return data
    }
    return JSON.stringify(data)
  }]
})
axiosInstance.defaults.timeout = 60000
axiosInstance.interceptors.request.use(config => {
    return config
}, err => {
  return Promise.reject(err)
})
axiosInstance.interceptors.response.use(data => {
    if (data && data.status === 200) {
        return data
    }
}, err => {
  toast('网络异常')
  // router.push('/login');
  return Promise.reject(err)
})
export default axiosInstance
